package com.example.goatstore;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CrearEmpresaActivity extends Activity {
	private EditText email;
	private EditText nombre;
	private EditText numero;
	
	@Override 
	public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.agregar_empresa_desde_admin);
        
        nombre = (EditText) findViewById(R.id.editTextNombre);
		email = (EditText) findViewById(R.id.editTextEmail);
		numero = (EditText) findViewById(R.id.editText1);
        
        ((Button) findViewById(R.id.buttonCancelar)).setOnClickListener(new OnClickListener() {
        	
			public void onClick(View v) {
				finish();
        	}
		});
        
        ((Button) findViewById(R.id.buttonAgregar)).setOnClickListener(new OnClickListener() {
        	
			public void onClick(View v) {
				if (nombre.getText().toString().compareTo("")==0){
					Toast.makeText(getApplicationContext(),
							"Por Favor Ingrese Nombre", Toast.LENGTH_SHORT).show();
				} 
				else if(email.getText().toString().compareTo("")==0 || email.getText().toString().compareTo(" ")==0){
					Toast.makeText(getApplicationContext(),
							"Por Favor Ingrese Email", Toast.LENGTH_SHORT).show();
				}
				else if(numero.getText().toString().compareTo("")==0 || numero.getText().toString().compareTo(" ")==0){
					Toast.makeText(getApplicationContext(),
							"Por Favor Ingrese número de sucursales", Toast.LENGTH_SHORT).show();
				}
				else {
					agregarEmpresa();
				}
        	}

			private void agregarEmpresa() {
				String name = nombre.getText().toString();
				String correo = email.getText().toString();
				int radio = 10;
				int number = Integer.parseInt(numero.getText().toString());
				if(control.ControlUsuario.crearUsuario(name, name, correo, correo, "empresa", number, radio)){
					Toast.makeText(getApplicationContext(),
							"Empresa registrada exitosamente", Toast.LENGTH_SHORT).show();	
					Intent intent = new Intent(CrearEmpresaActivity.this, ListaEmpresaActivity.class);   	    	            	
        			startActivity(intent);
				}
				else{
					Toast.makeText(getApplicationContext(),
							"Error", Toast.LENGTH_SHORT).show();
        		}
			}
		});
	}
	
}
